package com.example.demo.product.controller;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.example.demo.product.ProductDto;
import com.example.demo.product.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.TimeUnit;

@RequestMapping
@RestController
public class ProductController {

    @Autowired
    ProductService productService;

    @SentinelResource("getProduct")
    @GetMapping("/{pid}")
    public ProductDto getProduct(@PathVariable("pid") String productId) {
        ProductDto productDto = productService.getProduct(productId);
        try {
            TimeUnit.SECONDS.sleep(2);
        } catch (InterruptedException e) {

        }
        return productDto;
    }


}
